package com.mrd.gtimp.business.service;

import com.mrd.base.BaseBiz;
import com.mrd.gtimp.business.entity.PackingListDetailed;
import com.mrd.spring.repository.BaseRepository;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

@Service
public class PackingListDetailedBiz extends BaseBiz<PackingListDetailed> {


    @Resource
    // 该处指定注入BaseRepository的dao对象
    @Qualifier("packingListDetailedDao")
    public void setBaseRepository(BaseRepository<PackingListDetailed, String> baseRepository) {
        super.baseRepository = baseRepository;
    }

    /**
     * 根据商品id 查询装箱单详细信息
     */
    public PackingListDetailed findCommdetailByid(String commodityId) {
        if (StringUtils.isNotEmpty(commodityId)) {
            try {
                Map<String, Object> map = new HashedMap();
                map.put("commodityId", commodityId);
                String hql = "select t.id,t.goods_gross_weight,t.goods_net_weight " +
                        " from com.mrd.gtimp.business.entity.PackingListDetailed t" +
                        " inner join com.mrd.gtimp.business.entity.Commodity c" +
                        " on c.id=t.commodity.id " +
                        " where c.id=:commodityId ";
                List<Object> object = findObjectByHql(hql, 0, 1, map);
                for (Object s : object) {
                    Object[] obj = (Object[]) s;
                    PackingListDetailed p = new PackingListDetailed();
                    p.setId(obj[0].toString());
                    p.setGoods_gross_weight(obj[1].toString());
                    p.setGoods_net_weight(obj[2].toString());
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }


}
